package o;

import android.graphics.Rect;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.HorizontalScrollView;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;

public class cjy {
    protected float ʻ = 0.0f;
    protected float ʽ = 0.0f;
    protected View ˊ;
    protected long ˋ = 0;
    protected long ˎ = 0;
    protected int ˏ;
    protected Rect ॱ = new Rect();
    protected boolean ᐝ = false;

    public interface d {
        boolean ˋˋ();

        boolean ˋᐝ();

        boolean ˌ();

        boolean ˎˎ();
    }

    public cjy(ViewPager viewPager) {
        ˎ(viewPager, 1);
    }

    public cjy(HorizontalScrollView horizontalScrollView) {
        ˎ(horizontalScrollView, 1);
    }

    public cjy(RecyclerView recyclerView) {
        ˎ(recyclerView, 1);
    }

    private void ˎ(View view, int i) {
        if (view instanceof d) {
            this.ˊ = view;
            this.ˏ = i;
            view.setOverScrollMode(2);
            return;
        }
        throw new ClassCastException("View is not BounceView");
    }

    public boolean ˋ(MotionEvent motionEvent) {
        if (motionEvent.getAction() == 0) {
            this.ʽ = 0.0f;
            this.ʻ = 0.0f;
            this.ˎ = System.currentTimeMillis();
            if (this.ॱ.isEmpty()) {
                this.ॱ.set(ʽ(), ᐝ(), ʻ(), ʼ());
            }
        }
        return false;
    }

    public boolean ˏ(MotionEvent motionEvent) {
        return ˊ(motionEvent);
    }

    protected boolean ˊ(MotionEvent motionEvent) {
        if (motionEvent.getAction() != 2 && motionEvent.getAction() != 1 && motionEvent.getAction() != 3) {
            return false;
        }
        if (motionEvent.getAction() == 1 || motionEvent.getAction() == 3) {
            if (this.ᐝ) {
                this.ᐝ = false;
                this.ˋ = System.currentTimeMillis();
                ॱ();
            }
            this.ॱ.setEmpty();
            return false;
        } else if (this.ˏ == 1) {
            return ॱ(motionEvent);
        } else {
            if (this.ˏ == 0) {
                return ˎ(motionEvent);
            }
            return false;
        }
    }

    private boolean ˎ(MotionEvent motionEvent) {
        if (!ˊ() && !ˎ()) {
            return false;
        }
        float y = motionEvent.getY();
        float f = y - this.ʻ;
        if (this.ʻ == 0.0f) {
            f = 0.0f;
        }
        this.ʻ = y;
        if (ˊ() && ᐝ() + ((int) (f * 0.5f)) > this.ॱ.top) {
            ˋ(0.0f, f);
        }
        if (ˎ() && ʼ() + ((int) (f * 0.5f)) < this.ॱ.bottom) {
            ˋ(0.0f, f);
        }
        return this.ᐝ;
    }

    protected boolean ॱ(MotionEvent motionEvent) {
        if (!ˏ() && !ˋ() && motionEvent.getAction() != 2) {
            return false;
        }
        float x = motionEvent.getX();
        float f = x - this.ʽ;
        if (this.ʽ == 0.0f) {
            f = 0.0f;
        }
        this.ʽ = x;
        if (ˏ() && ʽ() + ((int) (f * 0.5f)) > this.ॱ.left) {
            ˋ(f, 0.0f);
        }
        if (ˋ() && ʻ() + ((int) (f * 0.5f)) < this.ॱ.right) {
            ˋ(f, 0.0f);
        }
        return this.ᐝ;
    }

    protected void ˋ(float f, float f2) {
        this.ᐝ = true;
        int i = (int) (f * 0.5f);
        int i2 = (int) (0.5f * f2);
        int ʽ = ʽ();
        int ᐝ = ᐝ();
        ᐝ += i2;
        this.ˊ.layout(ʽ + i, ᐝ, i + ʻ(), i2 + ʼ());
    }

    protected void ॱ() {
        long j = 350;
        long j2 = (long) (((float) (this.ˋ - this.ˎ)) * 0.3f);
        if (j2 <= 350) {
            if (j2 < 100) {
                j = 100;
            } else {
                j = j2;
            }
        }
        Animation animation = null;
        if (this.ˏ == 1) {
            animation = new TranslateAnimation((float) (ʽ() - this.ॱ.left), 0.0f, 0.0f, 0.0f);
            animation.setInterpolator(new kn());
        } else if (this.ˏ == 0) {
            animation = new TranslateAnimation(0.0f, 0.0f, (float) (ᐝ() - this.ॱ.top), 0.0f);
        }
        if (animation != null) {
            animation.setDuration(j);
            this.ˊ.startAnimation(animation);
        }
        this.ˊ.layout(this.ॱ.left, this.ॱ.top, this.ॱ.right, this.ॱ.bottom);
    }

    protected boolean ˏ() {
        try {
            return ((d) this.ˊ).ˌ();
        } catch (Exception e) {
            Logger.e("BounceHandler", "isLeft() " + e.toString());
            return false;
        }
    }

    protected boolean ˋ() {
        try {
            return ((d) this.ˊ).ˋˋ();
        } catch (IndexOutOfBoundsException e) {
            Logger.ˋ("BounceHandler", "isRight() IndexOutOfBoundsException " + e.toString());
            return false;
        } catch (ClassCastException e2) {
            Logger.ˋ("BounceHandler", "isRight() ClassCastException " + e2.toString());
            return false;
        } catch (Exception e3) {
            Logger.ˋ("BounceHandler", "isRight() Exception " + e3.toString());
            return false;
        }
    }

    protected boolean ˊ() {
        try {
            return ((d) this.ˊ).ˎˎ();
        } catch (ClassCastException e) {
            Logger.e("BounceHandler", "isTop() " + e.toString());
            return false;
        }
    }

    protected boolean ˎ() {
        try {
            return ((d) this.ˊ).ˋᐝ();
        } catch (Exception e) {
            Logger.e("BounceHandler", "isBottom() " + e.toString());
            return false;
        }
    }

    protected int ʽ() {
        return this.ˊ.getLeft();
    }

    protected int ʻ() {
        return this.ˊ.getRight();
    }

    protected int ᐝ() {
        return this.ˊ.getTop();
    }

    protected int ʼ() {
        return this.ˊ.getBottom();
    }
}
